/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[TestFrame.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package swing.awt;

import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class TestFrame {

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				SimpleFrame frame = new SimpleFrame();
				frame.setVisible(true);// 设置窗体可见性
				frame.setResizable(true);// 设置窗体是否可调节大小
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置关闭操作
			}
		});
	}
}

/**
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 *
 */
class SimpleFrame extends JFrame {

	private static final long serialVersionUID = 5906987028247950443L;

	// 默认的屏幕宽度
	private static final int DEFAULT_WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;

	// 默认的屏幕高度
	private static final int DEFAULT_HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;

	public SimpleFrame() {
		// 读取图片
		Image image = Toolkit.getDefaultToolkit()
				.getImage(SimpleFrame.class.getClassLoader().getResource("__/icon.gif"));

		this.setSize(DEFAULT_WIDTH / 2, DEFAULT_HEIGHT / 2);// 设置窗体的大小
		setTitle("Simple Frame");// 设置窗体的标题
		setLocationByPlatform(true);// 设置窗体出现的位置
		setIconImage(image); // 设置图片
		// this.setUndecorated(true);// 取消框架装饰
		// this.setExtendedState(Frame.MAXIMIZED_BOTH);// 设置窗体最大显示

		getContentPane().add(new JPanel() {
			private static final long serialVersionUID = 4600291620307701574L;

			@Override
			protected void paintComponent(Graphics g) {
				g.drawString("My First GUI app", getWidth() / 2, getHeight() / 2);
			}
		});
	}
}
